

import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
import P02 from './P02';
import P03 from './P03';
import P06 from './P06';

import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
export default async function a021(fd: IFeidaoAiBrowserComponent, role_allot_id: string, _id: string, ids: Array<{}>) {
	//  调用事件
	set(fd, 'role_allot_id', role_allot_id);
	const productid = get(fd, 'productid');
	const query = { productid, role_allot_id };
	remove(fd, 'allot_group');
	show_loading();
	const data = await nodejs<{ length: number }>('roler/zj-000004/s018', query);
	hide_loading();
	if (data.length === 0) {
		render(fd, '', P02, 'P02', 'inner');
	} else {
		render(fd, data, P02, 'P02', 'inner');
		if (_id) {
			if (_id === 'hebing') {
				render(fd, '', P06, 'P06', 'inner');
				render(fd, '', P03, 'P03', 'inner');
			} else {
				const items = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-id2="' + _id + '"]');
				set_node_cls(items, 'bg-c', true);
				const _id2 = items.getAttribute('data-feidao-id2');
				const connector = items.getAttribute('data-feidao-connector');
				const group_id = items.getAttribute('data-feidao-group_id');
				const group = items.getAttribute('data-feidao-group');
				set(fd, 'allot_group', {
					id: _id2, connector, group_id, group
				});
			}
		}
		if (ids) {
			if (ids.length !== 0) {

				ids.map((v: string) => {
					if (v) {
						fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id4="' + v + '"]').checked = true;
					}
				});
			}
		}
	}
}
